<?php
/*
|------------------------------------------------------------------|
|	Level5 - Wordpress Theme Framework
|
|	Copyright (c) Brixter de Leon
|	http://frostproject.org
|	deleon.brixter@gmail.com
|
|	This program is free software; you can redistribute it and/or
|	modify it under the terms of the GNU General Public License
|	as published by the Free Software Foundation; either version 2
|	of the License, or (at your option) any later version.
|
|	This program is distributed in the hope that it will be useful,
|	but WITHOUT ANY WARRANTY; without even the implied warranty of
|	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
|	GNU General Public License for more details.
|
|	You should have received a copy of the GNU General Public License
|	along with this program; if not, write to the Free Software
|	Foundation, Inc., 51 Franklin Street, Fifth Floor, 
|	Boston, MA  02110-1301, USA.
|------------------------------------------------------------------|
*/

if ( ! defined( 'direct_access' ) ) { die( 'Level5' ); }

print "\n" . '<div class="wrap">' . "\n\t";
print level5_header_icon();
print "\n\t" . '<h2>' . level5_title() . '</h2>' . "\n";
print "\t" . '<ins class="top_gap"></ins>' . "\n";
foreach ( $settings as $value )
{
	switch ( $value['type'] )
	{
		case 'status' :
			if ( $_REQUEST['saved'] )
			{
				print "\t\t" . '<div id="message" class="updated fade"><p>' . $value['update'] . '</p></div>' . "\n";
			}
			elseif ( $_REQUEST['reset'] )
			{
				print "\t\t" . '<div id="message" class="updated fade"><p>' . __( 'All options has been restored to factory setting.', 'level5' ) . '</p></div>' . "\n";
			}
			elseif ( $_REQUEST['file_type'] )
			{
				print "\t\t" . '<div id="message" class="updated fade"><p>' . __( 'Upload failed. Please check file type.', 'level5' ) . '</p></div>' . "\n";
			}
			elseif ( $_REQUEST['file_size'] )
			{
				print "\t\t" . '<div id="message" class="updated fade"><p>' . __( 'Upload failed. Please check file size.', 'level5' ) . '</p></div>' . "\n";
			}
			elseif ( $_REQUEST['file_write'] )
			{
				print "\t\t" . '<div id="message" class="updated fade"><p>' . __( 'Upload failed. Please check if <sup>[child]</sup> directory is writable.', 'level5' ) . '</p></div>' . "\n";
			}
			elseif ( $_REQUEST['file_failed'] )
			{
				print "\t\t" . '<div id="message" class="updated fade"><p>' . __( 'Upload failed. Please try again.', 'level5' ) . '</p></div>' . "\n";
			}
		break;
		case 'input' :
			if ( get_settings( $value['id'] ) != '' )
			{
				$set_value = get_settings( $value['id'] );
			}
			else
			{
				$set_value = $value['value'];
			}
			if ( $value['desc'] == '' || ! $value['desc'] )
			{
				$desc = null;
			}
			else
			{
				$desc = '<dfn>' . $value['desc'] . '</dfn>';
			}
			if ( $value['class'] == '' || ! $value['class'] )
			{
				$class = null;
			}
			else
			{
				$class = ' class="' . $value['class'] . '"';
			}
			/*
			if ( $value['sanitize'] == 'numeric' )
			{
				$sanitize = level5_sanitize( stripslashes_deep( $set_value ), 'numeric' );
			}
			elseif ( $value['sanitize'] == 'alphabetic' )
			{
				$sanitize = level5_sanitize( stripslashes_deep( $set_value ), 'alphabetic' );
			}*/
			print "\t\t\t" . '<tr valign="middle" class="' . $value['tr_class'] . '">' . "\n";
			print "\t\t\t\t" . '<th scope="row"><label for="' . $value['id'] . '">' . $value['title'] . $desc . '</label></th>' . "\n";
			print "\t\t\t\t" . '<td><input type="text" id="' . $value['id'] . '" name="' . $value['id'] . '"' . $class . ' value="' . stripslashes_deep( $set_value ) . '" /></td>' . "\n";
			print "\t\t\t" . '</tr>' . "\n";
		break;
		case 'textarea' :
			if ( get_settings( $value['id'] ) != '' )
			{
				$set_value = get_settings( $value['id'] );
			}
			else
			{
				$set_value = $value['value'];
			}
			if ( $value['desc'] == '' || ! $value['desc'] )
			{
				$desc = null;
			}
			else
			{
				$desc = '<dfn>' . $value['desc'] . '</dfn>';
			}
			if ( $value['class'] == '' || ! $value['class'] )
			{
				$class = null;
			}
			else
			{
				$class = ' class="' . $value['class'] . '"';
			}
			if ( $value['rows'] == '' || ! $value['rows'] )
			{
				$rows = null;
			}
			else
			{
				$rows = ' rows="' . $value['rows'] . '"';
			}
			if ( $value['cols'] == '' || ! $value['cols'] )
			{
				$cols = null;
			}
			else
			{
				$cols = ' cols="' . $value['cols'] . '"';
			}
			print "\t\t\t" . '<tr valign="middle" class="' . $value['tr_class'] . '">' . "\n";
			print "\t\t\t\t" . '<th scope="row"><label for="' . $value['id'] . '">' . $value['title'] . $desc . '</label></th>' . "\n";
			print "\t\t\t\t" . '<td><textarea id="' . $value['id'] . '" name="' . $value['id'] . '"' . $class . $rows . $cols . '>' . stripslashes_deep( $set_value ) . '</textarea></td>' . "\n";
			print "\t\t\t" . '</tr>' . "\n";
		break;
		case 'upload' :
			if ( $value['desc'] == '' || ! $value['desc'] )
			{
				$desc = null;
			}
			else
			{
				$desc = '<dfn>' . $value['desc'] . '</dfn>';
			}
			if ( $value['class'] == '' || ! $value['class'] )
			{
				$class = null;
			}
			else
			{
				$class = ' class="' . $value['class'] . '"';
			}
			print "\t\t\t" . '<tr valign="middle" class="' . $value['tr_class'] . '">' . "\n";
			print "\t\t\t\t" . '<th scope="row"><label for="upload">' . $value['title'] . $desc . '</label></th>' . "\n";
			print "\t\t\t\t" . '<td><input type="file" id="upload" name="file"' . $class . ' /></td>' . "\n";
			print "\t\t\t" . '</tr>' . "\n";
		break;
		case 'select' :
			if ( $value['desc'] == '' || ! $value['desc'] )
			{
				$desc = null;
			}
			else
			{
				$desc = '<dfn>' . $value['desc'] . '</dfn>';
			}
			if ( $value['class'] == '' || ! $value['class'] )
			{
				$class = null;
			}
			else
			{
				$class = ' class="' . $value['class'] . '"';
			}
			print "\t\t\t" . '<tr valign="middle" class="' . $value['tr_class'] . '">' . "\n";
			print "\t\t\t\t" . '<th scope="row"><label for="' . $value['id'] . '">' . $value['title'] . $desc . '</label></th>' . "\n";
			print "\t\t\t\t" . '<td>' . "\n";
			print "\t\t\t\t\t" . '<select id="' . $value['id'] . '" name="' . $value['id'] . '"' . $class . '>' . "\n";
			foreach ( $value['value'] as $option )
			{
				$selected = null;
				if ( $value['default'] == $option )
				{
					$selected .= ' selected="selected"';
				}
				print "\t\t\t\t\t\t" . '<option value="' . $option . '"' . $selected . '>' . $option . '</option>' . "\n";
			}
			print "\t\t\t\t\t" . '</select>' . "\n";
			print "\t\t\t\t" . '</td>' . "\n";
			print "\t\t\t" . '</tr>' . "\n";
		break;
		case 'checkbox' :
			if ( $value['desc'] == '' || ! $value['desc'] )
			{
				$desc = null;
			}
			else
			{
				$desc = '<dfn>' . $value['desc'] . '</dfn>';
			}
			if ( $value['class'] == '' || ! $value['class'] )
			{
				$class = ' class="checkbox"';
			}
			else
			{
				$class = ' class="' . $value['class'] . '"';
			}
			print "\t\t\t" . '<tr valign="middle" class="' . $value['tr_class'] . '">' . "\n";
			print "\t\t\t\t" . '<th scope="row"><label for="' . $value['id'] . '">' . $value['title'] . $desc . '</label></th>' . "\n";
			print "\t\t\t\t" . '<td>' . "\n";
			foreach ( $value['value'] as $option )
			{
				$selected = null;
				if ( $value['default'] == $option )
				{
					$selected .= ' checked="checked"';
				}
				print "\t\t\t\t\t" . '<input type="checkbox" id="' . $option . '" name="' . $value['id'] . '"' . $class . ' value="' . $option . '"' . $selected . ' /><label for="' . $option . '">' . $option . '</label><br />' . "\n";
			}
			print "\t\t\t\t" . '</td>' . "\n";
			print "\t\t\t" . '</tr>' . "\n";
		break;
		case 'radio' :
			if ( $value['desc'] == '' || ! $value['desc'] )
			{
				$desc = null;
			}
			else
			{
				$desc = '<dfn>' . $value['desc'] . '</dfn>';
			}
			if ( $value['class'] == '' || ! $value['class'] )
			{
				$class = ' class="radio"';
			}
			else
			{
				$class = ' class="' . $value['class'] . '"';
			}
			print "\t\t\t" . '<tr valign="middle" class="' . $value['tr_class'] . '">' . "\n";
			print "\t\t\t\t" . '<th scope="row"><label for="' . $value['id'] . '">' . $value['title'] . $desc . '</label></th>' . "\n";
			print "\t\t\t\t" . '<td>' . "\n";
			foreach ( $value['value'] as $option )
			{
				$selected = null;
				if ( $value['default'] == $option )
				{
					
					$selected .= ' checked="checked"';
				}
				print "\t\t\t\t\t" . '<input type="radio" id="' . $option . '" name="' . $value['id'] . '"' . $class . ' value="' . $option . '"' . $selected . ' /><label for="' . $option . '">' . $option . '</label><br />' . "\n";
			}
			print "\t\t\t\t" . '</td>' . "\n";
			print "\t\t\t" . '</tr>' . "\n";
		break;
		case 'submit' :
			if ( $value['class'] == '' || ! $value['class'] )
			{
				$class = null;
			}
			else
			{
				$class = ' class="' . $value['class'] . '"';
			}
			print "\t\t" . '<p class="submit">' . "\n";
			print "\t\t\t" . '<dfn><a href="' . level5_frameurl . '">' . level5_framename . ' ' . level5_framever . '</a></dfn>' . "\n";
			if ( $value['value'] != '' )
			{
				if ( $_GET['page'] != level5_sanitize( level5_page5 ) )
				{
					if ( $_GET['page'] == level5_sanitize( level5_page1 ) )
					{
						$page = level5_page1;
					}
					elseif ( $_GET['page'] == level5_sanitize( level5_page2 ) )
					{
						$page = level5_page2;
					}
					print "\t\t\t\t" . '<a class="reset" href="admin.php?page=' . level5_sanitize( $page ) . '&amp;action=reset">' . __( 'Reset', 'level5' ) . '</a>' . "\n";
				}
				print "\t\t\t" . '<input type="submit" name="submit"' . $class . ' value="' . $value['value'] . '" />' . "\n";
				print "\t\t\t" . '<input type="hidden" name="action" value="save" />' . "\n";
			}
			print "\t\t" . '</p>' . "\n";
		break;
		case 'textarea_write_css' :
			if ( get_settings( $value['id'] ) != '' )
			{
				$set_value = get_settings( $value['id'] );
			}
			else
			{
				$set_value = $value['value'];
			}
			if ( $_REQUEST['action'] == 'save' || $_REQUEST['action'] == 'reset' )
			{
				level5_css_write( $set_value, level5_files . level5_template . '.css' );
			}
			if ( $value['desc'] == '' || ! $value['desc'] )
			{
				$desc = null;
			}
			else
			{
				$desc = '<dfn>' . $value['desc'] . '</dfn>';
			}
			if ( $value['class'] == '' || ! $value['class'] )
			{
				$class = null;
			}
			else
			{
				$class = ' class="' . $value['class'] . '"';
			}
			if ( $value['rows'] == '' || ! $value['rows'] )
			{
				$rows = null;
			}
			else
			{
				$rows = ' rows="' . $value['rows'] . '"';
			}
			if ( $value['cols'] == '' || ! $value['cols'] )
			{
				$cols = null;
			}
			else
			{
				$cols = ' cols="' . $value['cols'] . '"';
			}
			print "\t\t\t" . '<tr valign="middle" class="' . $value['tr_class'] . '">' . "\n";
			print "\t\t\t\t" . '<th scope="row"><label for="' . $value['id'] . '">' . $value['title'] . $desc . '</label></th>' . "\n";
			print "\t\t\t\t" . '<td><textarea id="' . $value['id'] . '" name="' . $value['id'] . '"' . $class . $rows . $cols . '>' . stripslashes_deep( $set_value ) . '</textarea></td>' . "\n";
			print "\t\t\t" . '</tr>' . "\n";
		break;
		case 'about' :
			include( level5_child . level5_themedefault . '/about.php' );
		break;
		case 'theme_current' :
			if ( file_exists( level5_child . level5_template . '/functions.php' ) )
			{
				print "\t\t" . '<dl class="current-theme">' . "\n";
				print "\t\t\t" . '<dd>' . "\n";
				if ( file_exists( level5_template_path . '/screenshot.png' ) )
				{
					print "\t\t\t\t" . '<img src="' . level5_template_url . '/screenshot.png" width="245" height="185" alt="' . $level5_theme_info['name'] . '" />' . "\n";
				}
				else
				{
					print "\t\t\t\t" . '<img src="' . level5_wp_theme_url . level5_source_url . level5_images_url . '/level5-300x225.png" width="245" height="185" alt="' . $level5_theme_info['name'] . '" />' . "\n";
				}
				print "\t\t\t\t" . '<p>' . __( 'Author', 'level5' ) . ':&nbsp';
				if ( $level5_theme_info['author_url'] == '' )
				{
					print $level5_theme_info['author'];
				}
				else
				{
					print '<a href="' . $level5_theme_info['author_url'] . '">' . $level5_theme_info['author'] . '</a>';
				}
				print '</p>' . "\n";
				print "\t\t\t\t" . '<p>' . __( 'Version', 'level5' ) . ': ' . $level5_theme_info['version'] . '</p>' . "\n";
				print "\t\t\t\t" . '<p>&nbsp;</p>' . "\n";
				print "\t\t\t\t" . '<p>' . $level5_theme_info['desc'] . '</p>' . "\n";
				print "\t\t\t\t" . '<div class="clear"></div>' . "\n";
				print "\t\t\t" . '</dd>' . "\n";
				print "\t\t" . '</dl>' . "\n";
			}
		break;
		case 'themes_list' :
			print "\t\t" . '<dl class="theme-list">' . "\n";
			foreach( level5_get_directory( level5_child ) as $theme )
			{
				$theme_name = level5_sanitize( $theme, 'theme_name' );
				if ( $theme_name != level5_template )
				{
					include( level5_child . $theme_name . '/functions.php' );
					print "\t\t\t" . '<dd>' . "\n";
					if ( file_exists( level5_child . $theme_name . '/screenshot.png' ) )
					{
						print "\t\t\t\t" . '<ins><img src="' . level5_wp_theme_url . level5_child_url . $theme_name . '/screenshot.png" width="245" height="185" alt="' . $level5_theme_info['name'] . '" /><dfn>' . __( 'Version: ', 'level5' ) .  $level5_theme_info['version'] . '</dfn></ins>' . "\n";
					}
					else
					{
						print "\t\t\t\t" . '<ins><img src="' . level5_wp_theme_url . level5_source_url . level5_images_url . '/level5-300x225.png" width="245" height="185" alt="' . $level5_theme_info['name'] . '" /><dfn>' . __( 'Version: ', 'level5' ) .  $level5_theme_info['version'] . '</dfn></ins>' . "\n";
					}
					print "\t\t\t\t" . '<strong>' . $level5_theme_info['name'] . '</strong>' . "\n";
					if ( $level5_theme_info['author_url'] == '' )
					{
						print "\t\t\t\t" . '<dfn>' . __( 'By', 'level5' ) . ' ' . $level5_theme_info['author'] . '</dfn>' . "\n";
					}
					else
					{
						print "\t\t\t\t" . '<dfn>' . __( 'By', 'level5' ) . ' <a href="' . $level5_theme_info['author_url'] . '">' . $level5_theme_info['author'] . '</a></dfn>' . "\n";
					}
					print "\t\t\t\t" . '<ul>' . "\n";
					print "\t\t\t\t\t" . '<li><a href="admin.php?page=' . level5_sanitize( level5_page6 ) . '&amp;action=activate&amp;theme=' . $theme_name . '">' . __( 'Activate', 'level5' ) . '</a></li>' . "\n";
					print "\t\t\t\t\t" . '<li><a class="delete" href="admin.php?page=' . level5_sanitize( level5_page6 ) . '&amp;action=delete&amp;theme=' . $theme_name . '">' . __( 'Delete permanently', 'level5' ) . '</a></li>' . "\n";
					print "\t\t\t\t" . '</ul>' . "\n";
					print "\t\t\t" . '</dd>' . "\n";
				}
			}
			print "\t\t\t" . '<div class="clear"></div>' . "\n";
			print "\t\t" . '</dl>' . "\n";
		break;
		case 'hr' :
			print "\t\t" . '<hr />' . "\n";
		break;
		case 'h3' :
			if ( $value['id'] == '' || ! $value['id'] )
			{
				$id = null;
			}
			else
			{
				$id = ' id="' . $value['id'] . '"';
			}
			print "\t\t" . '<h3' . $id . '>' . $value['value'] . '</h3>' . "\n";
		break;
		case 'h4' :
			if ( $value['id'] == '' || ! $value['id'] )
			{
				$id = null;
			}
			else
			{
				$id = ' id="' . $value['id'] . '"';
			}
			print "\t\t" . '<h4' . $id . '>' . $value['value'] . '</h4>' . "\n";
		break;
		case 'start_table' :
			if ( $value['class'] == '' || ! $value['class'] )
			{
				$class = null;
			}
			else
			{
				$class = ' ' . $value['class'];
			}
			print "\t\t" . '<table class="form-table' . $class . '">' . "\n";
		break;
		case 'end_table' :
			print "\t\t" . '</table>' . "\n";
		break;
		case 'start_form' :
			if ( $_GET['page'] == level5_sanitize( level5_page5 ) )
			{
				print "\t" . '<form method="post" enctype="multipart/form-data">' . "\n";
			}
			else
			{
				print "\t" . '<form method="post">' . "\n";
			}
		break;
		case 'end_form' :
			print "\t" . '</form>' . "\n";
		break;
		case 'clear_gap' :
			print "\t" . '<ins class="clear_gap"></ins>' . "\n";
		break;
		case 'separator' :
			print "\t" . '<ins class="separator"></ins>' . "\n";
		break;
		case 'top_gap' :
			print "\t" . '<ins class="top_gap"></ins>' . "\n";
		break;
	}
}
print "\t" . '<ins class="clear_gap"></ins>' . "\n";
print '</div>' . "\n";
?>